
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>在线书城-全世界最大书城-详情</title>
        <link rel="shortcut icon" href="./images/favicon.ico" type="image/x-icon">
        <link rel="stylesheet" href="./css/commons.css">
        <link rel="stylesheet" href="/css/index.css">
        <link rel="stylesheet" href="http://at.alicdn.com/t/font_2808129_i5zudqxucsf.css">
        <link rel="stylesheet" href="./css/detailed.css">
        <script src="js/jquery.min.js"></script>
        <script src="js/toLogin.js"></script>
        <style>
            .index:hover{
                color: red;
            }
            .classify:hover{
                color: red;
            }
        </style>
    </head>
    <body>
          <!-- 头部开始 -->
          <div class="header flux clearfix">
            <div class="container">
                <h1 class="logo l">
                    <img src="./images/logo.jpeg" alt="">
                </h1>
                <ul class="shortcut">
                    <li>
                        <img src="./images/addr.png" alt="">
                        北京
                        <img src="./images/xia.png" alt="">
                     </li>
                    <li onclick="window.location.href='index.html'" class="index">首页</li>
                    <li class="classify" onclick="location.href='classify.html'">分类</li>
                    <li>
                        <img src="./images/search.png" alt="">
                        <input type="text" placeholder="搜索图书、课堂、文艺类">
                        <button>搜索</button>
                    </li>
                    <li>
                        <img src="./images/user.png" alt="">
                        <span  id="toLogin" onclick="window.location.href='login.html'" >登录</span>
                    </li>
                    <li>
                        <img src="./images/phone.png" alt="">
                        <span id="register" onclick="location.href='regist.html'">注册</span>
                    </li>
                    <li>
                        <div class="shopcart" onclick="window.location.href='./shopcart.html'">
                            <i class="iconfont icon-gouwuche" style="font-size:20px"></i>
                            <span>购物车</span>
                            <span id="shopNum"></span>
                        </div>
                    </li>
                </ul>
            </div>
         </div>
        <!-- 头部结束 -->
        <!-- 商品详情部分 -->
        <div class="bookdetail container">
            <div class="detail-img">
                <img  id="image" src="http://img3m6.ddimg.cn/70/2/28529296-1_w_5.jpg" alt="">
            </div>
            <div class="detail-content">
                <div class="detail-content-h">
                    <h3 id="titleTop" style="">社交新零售:5G时代的零售变军，读懂零售本质，抓住未来商机。</h3>
                    <p>
<!--                        <span>教你如何把货铺到消费者的枕头上，从而实现把货卖到爆。</span>-->
<!--                        <a href="#">吴晓波新作，一本书读懂三百年商业历史>></a>-->
                    </p>
                </div>

                <div class="detail-content-m">
                    <div class="detail-content-m-l">
                        <p id="author"></p>
                        <p id="stock"></p>
                        <p id="publisher"></p>
                        <p id="publishTime"></p>
                        <p>评分:
                            <i class="iconfont icon-start selectedstart"></i>
                            <i class="iconfont icon-start selectedstart"></i>
                            <i class="iconfont icon-start selectedstart"></i>
                            <i class="iconfont icon-start selectedstart"></i>
                            <i class="iconfont icon-start selectedstart"></i>
                        </p>
                    </div>
                    <div class="detail-content-m-r">
                        销售价:<span class="price"></span>
                    </div>
                </div>

                <div class="detail-content-b">
                    <span>购买数量</span>
                    <span onclick="reduceNum()">-</span>
                    <input type="text" value="1" class="num">
                    <span onclick="addNum()">+</span>
                    <button onclick="toBuy()">
                        <i class="iconfont icon-Money"></i>立即购买
                    </button>
                    <button onclick="toShop()">
                        <i class="iconfont icon-shop"></i>加入购物车
                    </button>
                </div>
            </div>
        </div>
        <!-- 商品详情部分结束 -->
        <div class="prointro container">
            <div>
                <span id="pdt">商品详情</span>
                <span id="pco">顾客评价</span>
                <i class="iconfont icon-qipao qp">
                    <i class="qc">5</i>
                </i>
            </div>
            <div class="prointro-prodetail">
                <h4>内容简介</h4>
                <p id="description" style="text-indent:2em;">
                </p>
            </div>
        </div>
          <!-- 底部栏开始 -->
          <div class="footer flux">
            <div class="f1 container">
                <ul>
                    <li>
                        <div class="tb1"></div>
                        <div class="tbc">品类齐全，轻松购物</div>
                    </li>
                    <li>
                        <div class="tb2"></div>
                        <div class="tbc">多仓直发，极速配送</div>
                   </li>
                    <li>
                        <div class="tb3"></div>
                        <div class="tbc">正品行货，精致服务</div>
                    </li>
                    <li>
                        <div class="tb4"></div>
                        <div class="tbc">天天低价，畅选无忧</div>
                    </li>
                </ul>
            </div>
            <div class="operator"></div>
            <div class="f2 container">
                <div>
                    <ul>
                        <li>购物指南</li>
                        <li>
                            <a href="#">购物流程</a>
                        </li>
                        <li>
                            <a href="#">会员介绍</a>
                        </li>
                        <li>
                            <a href="#">生活旅行/团购</a>
                        </li>
                        <li>
                            <a href="#">常见问题</a>
                        </li>
                        <li>
                            <a href="#">大家电</a>
                        </li>
                        <li>
                            <a href="#">联系客服</a>
                        </li>
                    </ul>
                </div>
                <div>
                    <ul>
                        <li>购物指南</li>
                        <li>
                            <a href="#">购物流程</a>
                        </li>
                        <li>
                            <a href="#">会员介绍</a>
                        </li>
                        <li>
                            <a href="#">生活旅行/团购</a>
                        </li>
                        <li>
                            <a href="#">常见问题</a>
                        </li>
                        <li>
                            <a href="#">大家电</a>
                        </li>
                        <li>
                            <a href="#">联系客服</a>
                        </li>
                    </ul>
                </div>
                <div>
                    <ul>
                        <li>购物指南</li>
                        <li>
                            <a href="#">购物流程</a>
                        </li>
                        <li>
                            <a href="#">会员介绍</a>
                        </li>
                        <li>
                            <a href="#">生活旅行/团购</a>
                        </li>
                        <li>
                            <a href="#">常见问题</a>
                        </li>
                        <li>
                            <a href="#">大家电</a>
                        </li>
                        <li>
                            <a href="#">联系客服</a>
                        </li>
                    </ul>
                </div>
                <div>
                    <ul>
                        <li>购物指南</li>
                        <li>
                            <a href="#">购物流程</a>
                        </li>
                        <li>
                            <a href="#">会员介绍</a>
                        </li>
                        <li>
                            <a href="#">生活旅行/团购</a>
                        </li>
                        <li>
                            <a href="#">常见问题</a>
                        </li>
                        <li>
                            <a href="#">大家电</a>
                        </li>
                        <li>
                            <a href="#">联系客服</a>
                        </li>
                    </ul>
                </div>
                <div>
                    <ul>
                        <li>购物指南</li>
                        <li>
                            <a href="#">购物流程</a>
                        </li>
                        <li>
                            <a href="#">会员介绍</a>
                        </li>
                        <li>
                            <a href="#">生活旅行/团购</a>
                        </li>
                        <li>
                            <a href="#">常见问题</a>
                        </li>
                        <li>
                            <a href="#">大家电</a>
                        </li>
                        <li>
                            <a href="#">联系客服</a>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="f3 container">
                <span>关于我们</span><span>|</span>
                <span>联系我们</span><span>|</span>
                <span>联系客服</span><span>|</span>
                <span>合作招商</span><span>|</span>
                <span>商家帮助</span><span>|</span>
                <span>营销中心</span><span>|</span>
                <span>English Site</span><span>|</span>
                <span>Media & IR</span>
            </div>
            <div class="f4 container">
                <span>Copyright &copy; 2020 - 2021  乐山LS.com 版权所有</span>
                <span>|</span>
                <span>消费者维权热线：4006067733经营证照</span>
                <span>|</span>
                <span>(川)网械平台备字(2020)第00004号</span>
                <span>|</span>
                <span>营业执照</span>
            </div>
        </div>
        <!-- 底部栏结束 -->

    </body>
<script src="js/toLogin.js"></script>
<script>
    let url=window.location.href;
    let arr=url.split("=");
    let id=arr[1];
    let price=0;
    let stock;

    $.ajax({
        url:"goods/findId",
        type:"post",
        data:{"id":id},
        datatype:"json",
        success:function (res) {
            $("#image").prop("src",res.image);
            $("#titleTop").text(res.name);
            $("#author").text("作者:"+res.author);
            $("#stock").text("库存:"+res.stock);
            $("#publisher").text("出版社:"+res.publisher);
            $("#publishTime").text("出版时间:"+res.pubtime);
            $("#description").text(res.description);
            $(".price").text("￥"+res.salesprice);
            price=res.salesprice;
            stock=res.stock;
        }
    });
    function addNum() {
        let num=parseInt($(".num").val());
        num=num+1;
        $(".num").val(num);
        if(num>stock){
            alert("超过库存数量");
            $(".num").val(stock);
        }
    }

    function reduceNum() {
        let num=parseInt($(".num").val());
        num=num-1;
        $(".num").val(num);
        if(num<1){
            alert("数量不足1");
            $(".num").val(1);
        }
    }

    function toBuy() {

        $.ajax({
            url:"order/toBuy",
            type:"get",
            datatype:"json",
            success:function (res) {
                if(res.code==500){
                    alert("你还没登陆，请先登录");
                    window.location.href="login.html";
                }else
                    window.location.href="pay.html";

            }

        });
    }

    function toShop(){
        let nums=$(".num").val();
        $.ajax({
            url:"cart/toCart",
            type:"get",
            datatype:"json",
            data:{
                "userid":sessionStorage.getItem("userid"),
                "goodsid":id,
                "price":price,
                "nums":nums,
            },
            success:function (res) {
                console.log(res);
                if(res.code==500){
                    alert(res.message)
                    if(res.message=="你还没有登录"){
                        window.location.href="login.html";
                    }
                }
                else{
                    alert("加入购物车成功");
                    window.location.href="shopcart.html";
                }
            }

        });

    }
</script>
</html>